﻿using AFanDa.BLL.BLLService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace AFanDa.Api.Controllers
{
    public class BaseController : ApiController
    {
        protected LoginService _loginService = null;

        public BaseController()
        {
            _loginService = new LoginService();
        }
        public long GetTimestamp()
        {
            return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
        }
        static Random rd = new Random();
        public int GetRandom(int min, int max)
        {
            return rd.Next(min, max);
        }

        /// <summary>
        /// 获取当前用户
        /// </summary>
        /// <returns></returns>
        protected Dto.EF.Admin getCurrentUser()
        {
            var code = this.User.Identity.Name;

            var iq = _loginService.getUserByCode(code);

            return iq.Single();

        }

        /// <summary>
        /// 获取微信用户
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        protected Dto.EF.WxUser GetWxUser()
        {
            var phone = this.User.Identity.Name;

            var iq = _loginService.GetWxUser(phone);

            if (iq.Any())
            {
                return iq.Single();
            }
            else { 
                return null;
            }
        }

        // ddd
        // 我是傻逼
        // 董炎 lllll
        // 666
        // 彭思期 666
    }
}

